package ru.niir.goodfil.audit.ui.beans;

import ru.niir.goodfil.audit.domain.Event;
import ru.niir.goodfil.audit.ui.extractors.*;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: Кирилл
 */
public class LogsDataTableBean {
    private List<Row> rows;

    public void init(List<Event> events) {
        System.out.println("Events: " + events.size());

        EventValueExtractor valueExtractor = new EventValueExtractor();
        EventTypeExtractor typeExtractor = new EventTypeExtractor();
        EventDescriptionExtractor descriptionExtractor = new EventDescriptionExtractor();
        EventAttachmentExtractor attachmentExtractor = new EventAttachmentExtractor();
        EventClientIdExtractor clientIdExtractor = new EventClientIdExtractor();
        EventClientNameExtractor clientNameExtractor = new EventClientNameExtractor();
        EventGoodIdExtractor goodIdExtractor = new EventGoodIdExtractor();
        EventGoodCodeExtractor goodCodeExtractor = new EventGoodCodeExtractor();
        EventGoodNameExtractor goodNameExtractor = new EventGoodNameExtractor();
        EventPriceExtractor priceExtractor = new EventPriceExtractor();

        rows = new ArrayList<Row>();

        for (Event event : events) {
            Row row = new Row();
            row.setIp(event.getIp());
            row.setLogin(event.getLogin());
            row.setDate(event.getDate());

            row.setValue(String.valueOf(valueExtractor.extract(event)));
            row.setType(String.valueOf(typeExtractor.extract(event)));
            row.setDescription(String.valueOf(descriptionExtractor.extract(event)));
            row.setAttachment(String.valueOf(attachmentExtractor.extract(event)));

            row.setClientId(String.valueOf(clientIdExtractor.extract(event)));
            row.setClientName(String.valueOf(clientNameExtractor.extract(event)));
            row.setGoodId(String.valueOf(goodIdExtractor.extract(event)));
            row.setGoodCode(String.valueOf(goodCodeExtractor.extract(event)));
            row.setGoodName(String.valueOf(goodNameExtractor.extract(event)));
            row.setPrice(String.valueOf(priceExtractor.extract(event)));

            rows.add(row);
        }
    }

    public void clear() {
        rows = null;
    }

    public static class Row {
        private Timestamp date;
        private String ip;
        private String login;

        private String clientId;
        private String goodId;
        private String orderId;

        private String clientName;
        private String goodCode;
        private String goodName;
        private String price;

        private String type;
        private String value;
        private String description;
        private String attachment;

        public Timestamp getDate() {
            return date;
        }

        public void setDate(Timestamp date) {
            this.date = date;
        }

        public String getIp() {
            return ip;
        }

        public void setIp(String ip) {
            this.ip = ip;
        }

        public String getLogin() {
            return login;
        }

        public void setLogin(String login) {
            this.login = login;
        }

        public String getClientId() {
            return clientId;
        }

        public void setClientId(String clientId) {
            this.clientId = clientId;
        }

        public String getGoodId() {
            return goodId;
        }

        public void setGoodId(String goodId) {
            this.goodId = goodId;
        }

        public String getOrderId() {
            return orderId;
        }

        public void setOrderId(String orderId) {
            this.orderId = orderId;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getAttachment() {
            return attachment;
        }

        public void setAttachment(String attachment) {
            this.attachment = attachment;
        }

        public String getClientName() {
            return clientName;
        }

        public void setClientName(String clientName) {
            this.clientName = clientName;
        }

        public String getGoodCode() {
            return goodCode;
        }

        public void setGoodCode(String goodCode) {
            this.goodCode = goodCode;
        }

        public String getGoodName() {
            return goodName;
        }

        public void setGoodName(String goodName) {
            this.goodName = goodName;
        }

        public String getPrice() {
            return price;
        }

        public void setPrice(String price) {
            this.price = price;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }
    }

    public List<Row> getRows() {
        return rows;
    }
}
